package mpcs
{
	import mpcs.NotiConst;
	import mpcs.controller.HistoryCommand;
	import mpcs.controller.LoginCommand;
	import mpcs.controller.RegCommand;
	import mpcs.controller.StartupCommand;
	import mpcs.controller.UserInfoCommand;
	import mpcs.model.vo.GlobalVO;
	import mpcs.mylibs.manager.ConManager;
	
	import org.puremvc.as3.patterns.facade.Facade;
	
	/**
	 *  
	 * @author zhangzuoqiang
	 */
	public class ApplicationFacade extends Facade {
		
		/**
		 * Register Commands with the Controller 
		 */
		override protected function initializeController( ) : void {
			
			super.initializeController();
			
			// 在此注册系统所有Command =============================================
			registerCommand( NotiConst.STARTUP, StartupCommand );// 启动
			registerCommand( NotiConst.S_LOGIN, LoginCommand );// 登录
			registerCommand( NotiConst.S_REGISTER, RegCommand );// 注册
			registerMultiCommand( UserInfoCommand, NotiConst.S_BASICINFO,
																				 NotiConst.S_SAVE_BASICINFO,
																				 NotiConst.S_CONTACTINFO,
																				 NotiConst.S_SAVE_CONTACTINFO,
																				 NotiConst.S_UPDATEPWD,
																				 NotiConst.S_MOBILELIST,
																				 NotiConst.S_SAVE_INIT_POSITION
												);// 用户信息相关
			registerCommand( NotiConst.S_POSITION_LIST, HistoryCommand );// 请求历史数据
			
			
		}
		
		/**
		 * Singleton Factory Method
		 */
		public static function getInstance() : ApplicationFacade {
			if ( instance == null )
				instance = new ApplicationFacade( );
			return ApplicationFacade( instance ) ;
		}
		
		/**
		 * Start the application
		 */
		 public function startup( app:* ):void {
			 GlobalVO.mpcsApp = app;
			 GlobalVO.mpcsApp.titleBar.doubleClickEnabled = false;
			 ConManager.initConnection();// 初始化连接 
			 
			 trace("正在初始化连接 ...  ");
			 
			 registerMediator( new MainMediator(app) );
			 sendNotification( NotiConst.STARTUP, app );
		 }
		 
		 /**
		  * 注册多个通知到同一个command里 
		  * @param commandClassRef
		  * @param notificationName
		  */
		 public function registerMultiCommand(commandClassRef:Class, ...notificationName):void
		 {
			 var count:int = notificationName.length;
			 for(var i:int=0;i<count;i++){
				 registerCommand(notificationName[i], commandClassRef);
			 }
		 }
		
	}
}